package test.my.com.myapplicationtest.roll_number;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import test.my.com.myapplicationtest.R;

/**
 * Author : Cooper
 * Time : 2017/2/6  15:37
 * Description : 数字翻滚
 */

public class RollNumberActivity extends Activity {

    @Bind(R.id.roll_tv)
    TextView rollTv;

    private double number = 13435.3453;
    private MultiScrollNumber scrollNumber;
    private HorizontalMultiScrollNumber horizontalMultiScrollNumber;
    private PunctuationTextView punctuationTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_roll_number_layout);
        ButterKnife.bind(this);
        horizontalMultiScrollNumber = (HorizontalMultiScrollNumber) findViewById(R.id.sn);
        horizontalMultiScrollNumber.setBackgroundColor(Color.GRAY);
        rollTv.postDelayed(timeCount,1000);

    }

    /**
     * 测试向上运动箭头动画
     */
    private void rollJianTouAnimator() {
        float startY = rollTv.getTranslationY();
        float height = rollTv.getHeight();
        Log.e("ah", "startY === " + startY);
        Log.e("ah", "height === " + height);
        rollTv.postDelayed(new Runnable() {
            @Override
            public void run() {
                setRollTvAnimator(0,rollTv.getHeight());
            }
        },500);
    }

    /**
     * 向上于东箭头动画
     * @param sy
     * @param ey
     */
    private void setRollTvAnimator(float sy,float ey) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(rollTv,"translationY",sy,-ey);
        objectAnimator.setDuration(1000);
        objectAnimator.setRepeatCount(2000);
        objectAnimator.setInterpolator(new LinearInterpolator());
        objectAnimator.setRepeatMode(ObjectAnimator.RESTART);
        objectAnimator.start();
    }

    private Runnable timeCount = new Runnable() {
        @Override
        public void run() {
            horizontalMultiScrollNumber.setNumber(number+"");
            number+=234.4;
            Log.e("ah ","RollNumberActivity  number  ==  "+number);
//            rollTv.postDelayed(this,1000);
        }
    };

    public static int getRandomInt(int a, int b) {
        if (a > b || a < 0)
            return -1;
        // 下面两种形式等价
        // return a + (int) (new Random().nextDouble() * (b - a + 1));
        return a + (int) (Math.random() * (b - a + 1));
    }

}
